set updatetime=100

cd D:\

set fileencodings=utf-8,ucs-bom,default,latin1,gb18030,gbk,gb2312,big5,cp936
set termencoding=utf-8
set encoding=utf-8
" Somet times we could use terminal font setting instead of setting font here
"set guifont=FantasqueSansMono\ Nerd\ Font:h9

set termguicolors
syntax on
set background=dark

" Auto Save and load folds
autocmd BufWinLeave * silent! mkview
autocmd BufWinEnter * silent! loadview

" Set Python provider
let g:python_host_prog  = 'C:\Users\WangY\AppData\Local\Programs\Python\Python27\python2.exe'
let g:python3_host_prog = 'C:\Users\WangY\AppData\Local\Programs\Python\Python39\python.exe'

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set number
set relativenumber
set scrolloff=5
set cindent
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab
"set nowrap
set cursorline
set colorcolumn=100

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

call plug#begin('C:\Users\WangY\.vim\plugged')
    Plug 'jiangmiao/auto-pairs'
    Plug 'MattesGroeger/vim-bookmarks'
    Plug 'tpope/vim-commentary'
    "Plug 'tpope/vim-surround'
    Plug 'Yggdroot/indentLine'
    "Plug 'easymotion/vim-easymotion'
    "Plug 'mbbill/undotree'
    Plug 'ntpeters/vim-better-whitespace'
    "Plug 'junegunn/vim-easy-align'
    Plug 'sainnhe/forest-night'
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'mhinz/vim-startify'
    Plug 'tpope/vim-fugitive'
    Plug 'neoclide/coc.nvim', { 'branch': 'release' }
    Plug 'mhinz/vim-signify'
    Plug 'junegunn/fzf',{ 'do': { ->fzf#install() } }
    Plug 'junegunn/fzf.vim'
    Plug 'liuchengxu/vista.vim'
    Plug 'sheerun/vim-polyglot'
    Plug 'pboettch/vim-cmake-syntax'
    "Plug 'ryanoasis/vim-devicons'
call plug#end()

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

colorscheme forest-night

" AutoPairs """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:AutoPairsMapBS = 0

" Wrap the word
imap <silent><leader>w <M-e>

" IndentLine """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:indentLine_fileTypeExclude = ['help', 'coc-explorer', 'vista', 'nerdtree', 'startify', 'undotree']

" BetterWhitespace """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:strip_whitespace_on_save = 1
let g:strip_whitespace_confirm = 0

" Airline """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:airline_powerline_fonts = 1

let g:airline#extensions#tabline#enabled   = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'

let g:airline#extensions#tabline#buffer_idx_mode = 1

nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
nmap <leader>- <Plug>AirlineSelectPrevTab
nmap <leader>= <Plug>AirlineSelectNextTab

" COC """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Some servers have issues with backup files
set nobackup
set nowritebackup

set hidden

" Coc extensions we would like to use
let g:coc_global_extensions =
    \['coc-json',
    \ 'coc-explorer',
    \ 'coc-vimlsp',
    \ 'coc-clangd'] " Run :CocConfig, then locate clangd.exe to the clang.path

" Don't pass messages to |ins-completion-menu|
set shortmess+=c

" Highling the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')

" Trigger completion
inoremap <silent><expr> <C-o> coc#refresh()

" Navigate diagnostics
nmap <silent><leader>E <Plug>(coc-diagnostic-prev)
nmap <silent><leader>e <Plug>(coc-diagnostic-next)

" GoTo code navigation
nmap <silent><leader>d <Plug>(coc-definition)
nmap <silent><leader>t <Plug>(coc-type-definition)
nmap <silent><leader>r <Plug>(coc-references)
nmap <silent><leader>i <Plug>(coc-implementation)

" Show documentation
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
    if (index(['vim','help'], &filetype)>=0)
        execute 'h '.expand('<cword>')
    else
        call CocActionAsync('doHover')
    endif
endfunction

" Signature help
imap <silent><leader>s <ESC>:call CocActionAsync('showSignatureHelp')<CR>a

" Scroll float window
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"

" Symbal renaming
nmap <leader>n <Plug>(coc-rename)

" Remap keys for applying codeAction to the current buffer
nmap <leader>a <Plug>(coc-codeaction)

" Apply AutoFix to problem on the current line
nmap <leader>f <Plug>(coc-fix-current)

" Switch between cpp and h files for C/C++
nmap <silent><leader>h :CocCommand clangd.switchSourceHeader<CR>

nmap <silent><leader>ce :CocCommand explorer<CR>

" FZF """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:fzf_layout = { 'down': '35%' }

" Vista """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

nmap <silent><leader>vt :Vista!!<CR>

let g:vista_default_executive = 'coc'

let g:vista_sidebar_width = 50

let g:vista#renderer#enable_icon = 0

" Signify """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:signify_priority = 5

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Head to start page
nmap <silent><F12> :Startify<CR>

" Buffers deleting
nmap <silent><leader>bd :bd<CR>
nmap <silent><leader>Bd :%bd<CR>

" Clear highlight
nmap <silent><leader>nh :noh<CR>

" Quick open and reload init.vim file
nmap <F9> :e $MYVIMRC<CR>
nmap <F10> :source $MYVIMRC<CR>

" Change split size
nnoremap <leader>_ :resize -
nnoremap <leader>+ :resize +
nnoremap <leader>< :vertical resize -
nnoremap <leader>> :vertical resize +

" Uncomit two lines below on windows, So nvim won't be frozen by the bug
nmap <C-z> <ESC>:echo "Don't press C-z on windows!"<CR>
vmap <C-z> <ESC>:echo "Don't press C-z on windows!"<CR>
